import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const token = ref('')
  const userInfo = ref({
    id: '',
    username: '',
    role: '',
    avatar: ''
  })

  // 设置用户信息
  function setUserInfo(info: any) {
    userInfo.value = info
  }

  // 设置 token
  function setToken(newToken: string) {
    token.value = newToken
  }

  // 清除用户信息
  function clearUserInfo() {
    userInfo.value = {
      id: '',
      username: '',
      role: '',
      avatar: ''
    }
    token.value = ''
  }

  return {
    token,
    userInfo,
    setUserInfo,
    setToken,
    clearUserInfo
  }
}) 